<template>
	<!-- 旧密码输入框 -->
	<input v-model="oldPassword" type="password" placeholder="请输入旧密码" class="input-field" />
	<!-- 新密码输入框 -->
	<input v-model="newPassword" type="password" placeholder="请输入新密码" class="input-field" />
	<!-- 确认新密码输入框 -->
	<input v-model="confimNewPassword" type="password" placeholder="请再次输入新密码" class="input-field" />
	<view class="ziti">{{content}}</view>
	<button @click="save" class="save-button">保存</button>
	<button @click="cancel" class="save-button">取消</button>
</template>

<script setup>
	import {
		ref
	} from 'vue';
	import {
			onLoad
		} from "@dcloudio/uni-app"
		import {updatePassWord} from "../../api/user.js"
	let oldPassword = ref('')
	let newPassword = ref('')
	let confimNewPassword = ref('')
	let oldoldpassword=ref('')
	let content=ref('')
	
	
		onLoad((option) => {
			// 获取传递参数
			console.log(option.password);
			oldoldpassword.value=option.password
		})
	
async function xiugai(password,oldPassword){
		let r1=await updatePassWord(password,oldPassword)
		console.log(r1.data);
		uni.showToast({
			title: '修改密码成功',
			icon: 'success'
		});
		uni.switchTab({
			url:"/pages/my/my"
		})
	}
	
	function save() {
		// console.log("保存");
		// console.log(oldPassword.value);
		// console.log(newPassword.value);
		// console.log(confimNewPassword.value);
		if(oldPassword.value==""||newPassword.value==""||confimNewPassword.value==""){
			content.value="请填写完整"
		}
		else if(oldPassword.value===newPassword.value){
			content.value="新密码不能和旧密码相同"
		}
		else if(newPassword.value!=confimNewPassword.value){
			content.value="两次输入的密码不一致"
		}
		else if(oldoldpassword.value!=oldPassword.value){
			content.value="旧密码错误"
		}
		else{
			
			// console.log("修改了");
			xiugai(newPassword.value,oldPassword.value)
		}
	}
	function cancel() {
		// console.log("取消");
		uni.switchTab({
			url:"/pages/my/my"
		})
	}
</script>

<style scoped>
	.input-field {
		border: 1px solid #ccc;
		border-radius: 5px;
		padding: 10px;
		margin-bottom: 20px;
	}

	.save-button {
		background-color: #007aff;
		color: white;
		padding: 10px;
		border-radius: 5px;
		text-align: center;
		margin-top: 20px;
	}
	.ziti{
		font-size: 30px;
		color: red;
	}
</style>